<template>
  <view class="advise">
    <AtForm>
      <AtTextarea 
        name='suggestContent' 
        :maxLength="200"
        type='text' 
        placeholder='请输入您的建议或者投诉' 
        v-model:value="suggestContent"
      />
      <AtButton style="margin-top: 30px;" type='primary'  @click="onSubmit">提交</AtButton>
      <AtButton style="margin-top: 30px;" type='secondary'  @click="gotoPage">历史投诉</AtButton>
    </AtForm>
  </view>
</template>

<script setup>
import { AtForm, AtTextarea, AtButton } from 'taro-ui-vue3'
import './index.scss'
import Taro from '@tarojs/taro'
import {ref} from 'vue'
import { add_complaint } from  '../../http/api'

const suggestContent = ref('')

const onSubmit = () => {
  if(suggestContent.value.length > 0) {
    add_complaint({c_complaint_content: suggestContent.value}).then(res => {
      if(res.code == '1000') {
        query_complaint()
        suggestContent.value = ''
        Taro.showToast({
            title: '建议收到，尽快给您处理',
            icon: 'none',
            duration: 2000
        })
      }
    })
  } else {
    Taro.showToast({
        title: '建议不能为空',
        icon: 'none',
        duration: 2000
    })
  }
}
// 跳转问题答案
const gotoPage = (row) => {
  Taro.navigateTo({
    url: `/pages/adviseList/index`
  })
}
Taro.showShareMenu({
  withShareTicket: true,
  menus: ['shareAppMessage', 'shareTimeline']
})
</script>
